package h0801;

import java.util.*;

/**
 * @author 不知名帅哥
 * @version 1.0
 * @description 转盘寿司
 * @date 2024/8/1 18:59
 */
public class TurnTableSushi {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] sushis = Arrays.stream(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
//        int[] arr = nextGreatSushi2(sushis);
//        StringJoiner joiner=new StringJoiner(" ");
//        for (int i : arr) {
//            joiner.add(i+"");
//        }
//
//        System.out.println(joiner);
        nextGreatSushi(sushis);
    }

    private static void nextGreatSushi(int[] sushis) {
        Deque<Integer> stack=new ArrayDeque<>();
        int n= sushis.length;
        //结果
        int[] res = Arrays.copyOfRange(sushis, 0, n);

        for (int i = 0; i < n*2; i++) {
            int num=sushis[i%n];
            while (!stack.isEmpty()&&sushis[stack.peek()]>num){
                Integer pop = stack.pop();
                res[pop]+=num;
            }
            // TODO 只有第一轮遍历时，才允许压栈，第二轮遍历时，只进行比较
            if (i<n){
                stack.push(i);
            }
        }
        System.out.println(Arrays.toString(res));
    }

    public static int[] nextGreatSushi2(int[] sushis) {
        List<Integer> res = new ArrayList<>();
        for (int i = 0; i < sushis.length; i++) {
            int temp = sushis[i];
            for (int j = i + 1; j < sushis.length + i; j++) {
                int newJ = j % (sushis.length);
                if (i ==newJ) continue;
                if (sushis[newJ] < sushis[i]) {
                    temp += sushis[newJ];
                    break;
                }
            }
            res.add(temp);
        }
        return res.stream().mapToInt(Integer::intValue).toArray();
    }

}
